package com.ssfGame.puremvc.view.module.title.vc
{
	import api.dataStruct.BuyItemVO;
	import api.dataStruct.FaceDataObj;
	import api.dataStruct.GetItemInfoVO;
	import api.dataStruct.ReadStoreVO;
	import api.dataStruct.SaveStoreVO;
	import api.dataStruct.ServerStoreVO;
	import api.dataStruct.SetFaceVO;
	import api.dataStruct.ShareWBVO;
	import api.dataStruct.UseItemVO;
	import api.event.CallFunName;
	
	import com.adobe.serialization.json.JSON;
	import com.game.api.APICore;
	import com.game.baseMc.BaseMc;
	import com.game.btnClass.BtnClass_bright;
	import com.game.data.GameStaticData;
	import com.game.utils.GlobalFun;
	import com.ssfGame.puremvc.StaticConst;
	import com.ssfGame.puremvc.view.mc.GameTestBtn;
	import com.ssfGame.puremvc.view.module.ModuleVC;
	
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.text.TextField;
	
	public class TitleVC extends ModuleVC
	{
		public static const INIT_PVP:String="init_pvp"//初始化pvp;
		private var _itemId:uint=12318;
		
		private var _btnListName:Array=["初始化PVP","购买道具","获取道具","使用道具","保存进度","读取进度","发表微博","显示表情","删除表情"];
		private var disTxt:TextField;
		public function TitleVC()
		{
			init();
		}
		private function init():void{
			StaticConst.apiCore.currClass=this//必须添加;
			StaticConst.apiCore.callAPIFun(CallFunName.A_SET_GAME_STATE,false);
			copyBtnList();
		}
		public function gc():void{
			
		}
		private function copyBtnList():void{
			for(var i:uint=0;i<_btnListName.length;i++){
				var _btn:GameTestBtn=new  GameTestBtn();
				var _point:Point=GlobalFun.getListPoint(i,7,112,40);
				_btn.x=28+_point.x;
				_btn.y=42+_point.y;
				_btn.id=i;
				_btn.txt.text=_btnListName[i];
				this.addChild(_btn);
				_btnEventList.push(new BtnClass_bright(_btn,btnClick,null,null,true));
			}
		}
		private function btnClick(e:MouseEvent):void{
			var _btn:GameTestBtn=e.currentTarget as GameTestBtn;
			switch(_btn.id){
				case 0:
					sendToMediator(INIT_PVP);
					break;
				case 1:
					buyItim();
					break;
				case 2:
					getOneItim();
					break;
				case 3:
					useItim();
					break;
				case 4:
					setStore();
					break;
				case 5:
					getStore();
					break;
				
				case 6:
					shareWB();
					break;
				case 7:
					showFace();
					break;
				case 8:
					delFace();
					break;
			}
		}
		private function showFace():void{
			APICore.getInstance().callAPIFun(CallFunName.A_SET_FACE_LIST,new SetFaceVO(true,new Point(100,100),faceCallBack));
		}
		private function delFace():void{
			APICore.getInstance().callAPIFun(CallFunName.A_SET_FACE_LIST,new SetFaceVO(false));
		}
		private function faceCallBack(data:FaceDataObj):void{
			trace("faceCallBack:"+data);
		}
		private function onShareWB(result:int):void{
			if(result==0){
				disTxt.text="发布到微博成功";
			}else{
				//失败
				disTxt.text="发布到微博失败";
			}
		}
		private function onSetStore(result:int):void{
			if(result==0){
				//success
				disTxt.text="保存数据成功";
			}else{
				disTxt.text="保存数据失败";
			}
		}
		private function onGetStore(store:ServerStoreVO):void{
			if(store.result==0){
				//success
				disTxt.text="读取数据成功:"+store.data;
			}else{
				//fail
				disTxt.text="读取数据失败:";
			}
		}
		
		private function onBuyItem(result:int,vo:BuyItemVO):void{
			var _vo:BuyItemVO=vo as BuyItemVO;
			var _des:String="道具购买";
			if(result==0){
				//success
				disTxt.text=_des+"成功"+_vo.toString();
			}else{
				disTxt.text=_des+"失败";
			}
			_vo=null;
		}
		private function onGetOneItem(data:*):void{
			var _des:String="道具查询";
			if(data.result==0){
				//success
				disTxt.text=_des+"成功"+JSON.encode(data);
			}else{
				disTxt.text=_des+"失败";
			}
		}
		private function onUseItem(result:int,vo:UseItemVO):void{
			var _vo:UseItemVO=vo as UseItemVO;
			var _des:String="道具使用";
			if(result==0){
				//success
				disTxt.text=_des+"成功"+_vo.toString();
			}else{
				disTxt.text=_des+"失败";
			}
			_vo=null;
		}
		
		//====================================
		//游戏调用API方法
		private function shareWB():void{
			StaticConst.apiCore.callAPIFun(CallFunName.A_SHARE_WB,new ShareWBVO("双人农场连连看,很好玩!http://www.3366.com/flash/82356.shtml","http://img.3366img.com/fileupload/flash/56/82356/base20121107173114/resource/gameImage/19454.jpg",onShareWB));
		}
		private function buyItim():void{
			StaticConst.apiCore.callAPIFun(CallFunName.A_BUY_ITIM,new BuyItemVO(_itemId,1,onBuyItem));
		}
		private function useItim():void{
			StaticConst.apiCore.callAPIFun(CallFunName.A_USE_ITIM,new UseItemVO(_itemId,1,onUseItem));
		}
		private function getOneItim():void{
			StaticConst.apiCore.callAPIFun(CallFunName.A_GET_ONE_ITIM,new GetItemInfoVO(_itemId,onGetOneItem));
		}
		private function setStore():void{
			disTxt.text="正在保存数据...";
			StaticConst.apiCore.callAPIFun(CallFunName.A_SAVE_STORE,new SaveStoreVO("战绩1","要保存的数据",1,1,onSetStore));
		}
		private function getStore():void{
			disTxt.text="正在读取数据...";
			StaticConst.apiCore.callAPIFun(CallFunName.A_READ_STORE,new ReadStoreVO(1,1,onGetStore));
			
		}
		
		
		
	}
}